package com.qf.base.controller;

import com.qf.base.domain.BaseGoods;
import com.qf.base.service.IBaseGoodsService;
import com.qf.common.annotation.Log;
import com.qf.common.core.controller.BaseController;
import com.qf.common.core.domain.AjaxResult;
import com.qf.common.core.page.TableDataInfo;
import com.qf.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * --- ONE PIECE ---
 *
 * @author yangjiangcheng
 * @date 2025/9/4
 * @desc
 */
@RestController
@RequestMapping("/tms/base/goods")
public class BaseGoodsController extends BaseController {
    @Autowired
    private IBaseGoodsService baseGoodsService;

    /**
     * 获取货物信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseGoods goods) {
        startPage();
        List<BaseGoods> list = baseGoodsService.selectGoodsList(goods);
        return getDataTable(list);
    }

    /**
     * 新增货物信息
     */
    @Log(title = "货物管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BaseGoods goods) {
        goods.setCreateBy(getUsername());
        return toAjax(baseGoodsService.insertGoods(goods));
    }

    /**
     * 根据货物Id获取详细信息
     */
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable Long goodsId) {
        return success(baseGoodsService.selectGoodsById(goodsId));
    }

    /**
     * 修改货物信息
     */
    @Log(title = "货物管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BaseGoods goods) {
        goods.setUpdateBy(getUsername());
        return toAjax(baseGoodsService.updateGoods(goods));
    }

    /**
     * 删除货物信息
     */
    @Log(title = "货物管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseGoodsService.deleteGoodsByIds(ids));
    }


}
